package br.unisinos.utils;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;


public class ClassUtils extends org.springframework.util.ClassUtils{

	
	/**
	 * invoca o getter do field, no obj passado
	 * @param obj
	 * @param field
	 * @return
	 * @throws NoSuchMethodException
	 * @throws IllegalAccessException
	 * @throws InvocationTargetException
	 */
	@SuppressWarnings("unchecked")
	public Object doGetterForField(Object obj, Field field, Class clazz) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
		String getterName = "get"+field.getName().substring(0,1).toUpperCase()+field.getName().substring(1);
		Method method = clazz.getDeclaredMethod(getterName, (Class[])null);
		Object object  = method.invoke(obj, (Object[])null);
		return object;
	}
	
	
	public void doSetterForField(Object obj,Object value, Field field, Class clazz) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException{
		String setterName = "set"+field.getName().substring(0,1).toUpperCase()+field.getName().substring(1);
		Method method = clazz.getDeclaredMethod(setterName, new Class[]{value.getClass()});
		method.invoke(obj, value);
	}
}






